<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>开票信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function confirmInvoiceInfo(id){
			var startTime = $("input[name='startTime']").val();
			var endTime = $("input[name='endTime']").val();
			var queryCode = $('#queryCode').val();
			var queryUserType = $('#queryUserType').val();
			var queryUserName = $('#queryUserName').val();
			var queryStatus = $('#queryStatus').val();
			var queryInvoiceType = $('#queryInvoiceType').val();
			var pageNo = $('#pageNo').val();
			var pageSize = $('#pageSize').val();
			var condition = "";
			if(startTime!=null && startTime!=''){
				condition = condition + '&startTime='+startTime;
			}
			if(endTime!=null && endTime!=''){
				condition = condition + '&endTime='+endTime;
			}
			if(queryCode!=null && queryCode!=''){
				condition = condition + '&queryCode='+queryCode;
			}
			if(queryUserType!=null && queryUserType!=''){
				condition = condition + '&queryUserType='+queryUserType;
			}
			if(queryUserName!=null && queryUserName!=''){
				condition = condition + '&queryUserName='+queryUserName;
			}
			if(queryStatus!=null && queryStatus!=''){
				condition = condition + '&queryStatus='+queryStatus;
			}
			if(queryInvoiceType!=null && queryInvoiceType!=''){
				condition = condition + '&queryInvoiceType='+queryInvoiceType;
			}
			if(pageNo!=null && pageNo!=''){
				condition = condition + '&pageNo='+pageNo;
			}
			if(pageSize!=null && pageSize!=''){
				condition = condition + '&pageSize='+pageSize;
			}
			$.ajax({
				url:'${ctx}/sys/commonUser/couldComfirm',
				data:{'id':id},
				async:false,
				success:function(result){
					console.log(result);
					if("1"==result){
						confirmx('确定已开票？','${ctx}/sys/commonUser/confirmInvoiceInfo?id='+id+condition);
					}else{
						showTip('该笔交易未完成，无法开票', '', 3000, 0);
						return ;
					}
				},
				error:function(e){
					console.log(e)
				}
			})
		}
		function resetFunc(){
			$("#searchForm input[type='text']").val("");
			$('#s2id_queryInvoiceType').find('.select2-chosen').html('所有');
			$("#queryInvoiceType").find("option")[0].selected='selected';
			$('#s2id_queryUserType').find('.select2-chosen').html('所有');
			$("#queryUserType").find("option")[0].selected='selected';
			$('#s2id_queryStatus').find('.select2-chosen').html('所有');
			$("#queryStatus").find("option")[0].selected='selected';
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/commonUser/invoiceInfoList">开票信息列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="invoiceInfo" action="${ctx}/sys/commonUser/invoiceInfoList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li>
				<label>交易编号：</label>
				<form:input path="queryCode" htmlEscape="false" maxlength="50" class="input-small"/>
			</li>
			<li>
				<label>发票类型：</label>
				<form:select path="queryInvoiceType" class="input-small">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('invoice_type')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li>
			<li>
				<label style="width:120px;">交易时间：</label>
				<input name="startTime" type="text" placeholder="开始时间" readonly="readonly" class="input-medium Wdate " 
			         value="<fmt:formatDate value="${invoiceInfo.startTime }" pattern="yyyy-MM-dd HH:mm:ss"/>"
			         onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
			     -
			     <input name="endTime" type="text" placeholder="结束时间" readonly="readonly" class="input-medium Wdate " 
			     value="<fmt:formatDate value="${invoiceInfo.endTime }" pattern="yyyy-MM-dd HH:mm:ss"/>"
			     onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/> 
			</li>
			</ul>
			<ul class="ul-form">
			<li>
				<label>用户：</label>
				<form:input path="queryUserName" htmlEscape="false" maxlength="50" class="input-small"/>
			</li>
			<li>
				<label>用户类型：</label>
				<form:select path="queryUserType" class="input-small">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('user_type')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li>
			<li>
				<label>状态：</label>
				<form:select path="queryStatus" class="input-small">
			    <form:option value="" label="所有"/>
			    <form:options items="${fns:getDictList('invoice_status')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
			    </form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="搜索"/></li>
			<li class="btns"><input class="btn btn-primary" type="button" value="重置" onclick="resetFunc()"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<div style="display:none;">
		<sys:message content="${message}"/>
	</div>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>序号</th>
				<th>交易编号</th>
				<th>交易时间</th>
				<th>用户类型</th>
				<th>用户</th>
				<th>状态</th>
				<th>发票类型</th>
				<th>开票金额</th>
				<th>查看发票</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="invoiceInfo" varStatus="index">
			<tr>
				<td>${index.index+1}</td>
			<c:choose>
				<c:when test="${invoiceInfo.userType==1}">
					<td><a href="${ctx}/sys/orders/form?id=${invoiceInfo.orderId}">${invoiceInfo.ordersCode}</a></td>
				</c:when>
				<c:otherwise>
					<td>${invoiceInfo.code}</td>
				</c:otherwise>
			</c:choose>
				<td><fmt:formatDate value="${invoiceInfo.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td>${fns:getDictLabel(invoiceInfo.userType, 'user_type', '')}</td>
				<td>${invoiceInfo.userName }</td>
				<td>${fns:getDictLabel(invoiceInfo.status, 'invoice_status', '')}</td>
				<td>${fns:getDictLabel(invoiceInfo.invoiceType, 'invoice_type', '')}</td>
				<td>￥${invoiceInfo.money }</td>
				<td><a href="${ctx}/sys/commonUser/invoiceInfoDetail?id=${invoiceInfo.id}">查看发票详情</a></td>
			<c:choose>
				<c:when test="${invoiceInfo.status==0}">
					<td><a href="javascript:;" onclick="confirmInvoiceInfo(${invoiceInfo.id})">确认开票</a></td>	
				</c:when>
				<c:otherwise>
					<td>--</td>
				</c:otherwise>
			</c:choose>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>